//
//  GetCustomerVisitAnalysisListApi.m
//  EMMApp
//
//  Created by Mac on 16/6/14.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "GetCustomerVisitAnalysisListApi.h"

#define myUrlMethod @"getCustomerVisitAnalysisList"
#define myUrlPath @"/appapi/getCustomerVisitAnalysisList"

@implementation GetCustomerVisitAnalysisListApi
{
    NSString *_body;
}
- (instancetype)initWithVisitTimeType:(NSString *)visitTimeType{
    self = [super init];
    if (self) {
        NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
        NSString *merchantId = [userdf objectForKey:@"merchantId"];
        NSString *userId = [userdf objectForKey:@"userNameId"];
        NSString *token = [userdf objectForKey:@"is_login"];
        NSString *projectCode = [userdf objectForKey:@"projectCode"];
        
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        [params setValue:apiVersion forKey:@"version"];
        [params setValue:[IDTools devId2] forKey:@"terminalCode"];
        [params setValue:merchantId forKey:@"merchantId"];
        [params setValue:userId forKey:@"userId"];
        [params setValue:token forKey:@"token"];
        [params setValue:projectCode forKey:@"projectCode"];
        [params setValue:visitTimeType forKey:@"visitTimeType"];
        _body = [@{@"params" : params} JSONString];
        NSLog(@"%@:\n %@%@?body=%@", myUrlMethod, apiBaseUrl, myUrlPath, _body);
    }
    return self;
}

#pragma mark - 父类继承拓展

- (NSString *)requestUrl
{
    return myUrlPath;
}

- (id)requestArgument
{
    return @{ @"body" : _body };
}

- (NSString *)methodString
{
    return myUrlMethod;
}


#pragma mark - 通用

- (GetCustomerVisitAnalysisList *)resultData
{
    id myObj = [IDTools jsonStrToObjc:self.responseString method:myUrlMethod];
    
    GetCustomerVisitAnalysisList *data = (GetCustomerVisitAnalysisList *)myObj;
    
    NSLog(@"%@ resultData is %@", myUrlMethod, data);
    
    return data;
}

- (BOOL)isSuccess
{
    NSString *str = [[self resultData] result];
    if ([NSString isStringEmpty:str] || ![str isEqualToString:@"1"]) {
        return NO;
    } else {
        return YES;
    }
}

@end
